﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Reflection;
using System.IO;

namespace PerformanceDude.MSBuildShellExtension
{
    public partial class AboutDialog : Window
    {
        public AboutDialog()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(AboutDialog_Loaded);
        }

        void AboutDialog_Loaded(object sender, RoutedEventArgs e)
        {
            string dllFilePath = Assembly.GetExecutingAssembly().Location;

            string appPath = System.IO.Path.GetDirectoryName(dllFilePath);

            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(dllFilePath);
            this.tbVersion.Text = fvi.ProductVersion;

            ConfigureHyperlink(
                hlPerformanceDude, 
                "mailto:info@performancedude.com");

            ConfigureHyperlink(
                hlRami,
                "mailto:rami.abughazaleh@gmail.com");

            ConfigureHyperlink(
                hlLex,
                "mailto:support@lextm.com");

            ConfigureHyperlink(
                hlCodeplex,
                "http://msbuildshellex.codeplex.com");

            ConfigureHyperlink(
                hlLicense,
                System.IO.Path.Combine(appPath, "License.rtf"));

            ConfigureHyperlink(
                hlHelp,
                System.IO.Path.Combine(appPath, "MSBuildShellEx.chm"));

            ConfigureHyperlink(
                hlDonate,
                "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=thomasardal%40gmail%2ecom&item_name=MSBuildShellExtension&buyer_credit_promo_code=&buyer_credit_product_category=&buyer_credit_shipping_method=&buyer_credit_user_address_change=&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=DK&bn=PP%2dDonationsBF&charset=UTF%2d8");
        }

        private void ConfigureHyperlink(Hyperlink hl, string uri)
        {
            hl.NavigateUri = new Uri(uri);
            hl.ToolTip = uri;
            hl.Click += new RoutedEventHandler(Hyperlink_Click);
        }

        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            Process.Start((sender as Hyperlink).NavigateUri.ToString());
        }
    }
}
